package com.jhh.pay.heli;

import com.alibaba.fastjson.JSONObject;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.jhh.pay.heli.bean.Bank;
import com.jhh.pay.heli.utils.FileIOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;

import java.lang.reflect.Type;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
@EnableConfigurationProperties
@SpringBootApplication
public class HelipayApplication {

	public static final SimpleDateFormat sSimpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmss");

	private static final Logger mLogger = LoggerFactory.getLogger(HelipayApplication.class);

	public static List<Bank> banks;

	//必要的操作
	static {
		mLogger.info("--------合利宝支付项目启动-------------");
		try {
			ClassLoader classLoader = HelipayApplication.class.getClassLoader();
			URL resource = classLoader.getResource("bankcode.json");
			String path = resource.getPath();
			String bankList = FileIOUtils.readFile2String(path);

			Gson gson = new Gson();
			Type type = new TypeToken<ArrayList<Bank>>() {}.getType();
			banks = gson.fromJson(bankList,type);

			/**
			 * 本地银行编码转换
			 */
			for (Bank bank : banks) {
				Bank.mBankMap.put(bank.getBankLocalCode(),bank.getBankCode());
			}

			mLogger.info("加载的银行参数: "+ JSONObject.toJSONString(banks));
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public static void main(String[] args) {
		SpringApplication.run(HelipayApplication.class, args);
	}
}
